import { http, HttpResponse } from 'msw'
import Mock from 'mockjs'
// // 导入
// export const importDB = http.post(
//   '/data/ed/user/database/import',
//   async ({ request }) => {
//     const data = await request.formData()
//     const file = data.get('fileData')

//     if (!file) {
//       return new HttpResponse('Missing document', { status: 400 })
//     }

//     if (!(file instanceof File)) {
//       return new HttpResponse('Uploaded document is not a File', {
//         status: 400,
//       })
//     }
//     await new Promise(resolve => {
//       setTimeout(resolve, 3000)
//     })
//     return HttpResponse.json({
//       contents: await file.text(),
//       success: true,
//     })
//   },
// )
// 导出
export const exportDB = http.post('/data/ed/user/database/export', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      url: 'testurl1111324',
    },
  })
})
// 新增
export const createFolder = http.post('/data/ed/user/file/createFolder', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {},
  })
})
// 更新文件占用状态
export const updateFileStatus = http.post(
  '/data/ed/user/file/updateFileStatus',
  () => {
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {},
    })
  },
)
// 上传
export const uploadFile = http.post(
  '/data/ed/user/file/upload',
  async ({ request }) => {
    const data = await request.formData()
    const file = data.get('fileData')

    if (!file) {
      return new HttpResponse('Missing document', { status: 400 })
    }

    if (!(file instanceof File)) {
      return new HttpResponse('Uploaded document is not a File', {
        status: 400,
      })
    }
    await new Promise(resolve => {
      setTimeout(resolve, 30000)
    })
    return HttpResponse.json({
      success: true,
      // contents: await file.text(),
    })
  },
)
// 下载
export const downloadFile = http.get('/data/ed/user/file/download', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {
      urlArr: ['www.baidu.com', 'www.baidu.com'],
    },
  })
})
// 复制
export const copyFile = http.post('/data/ed/user/file/copy', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {},
  })
})
// 重命名
export const renameFile = http.post('/data/ed/user/file/rename', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: {},
  })
})

// 查
export const getFileInfoList = http.post(
  '/data/ed/user/file/info',
  async () => {
    let strArray = ['occupy', 'publish']
    let filelist = Mock.mock({
      'list|10': [
        {
          dataId: '@string',
          fileName: '@name',
          'dataType|1': [0, 1],
          fileType: 'fileType55',
          version: '@string',
          gmtCreate: '@date(yyyy-MM-dd HH:mm:ss)',
          'gmtBatchUpload|1': ['2024-11-20 12:12:12', '2024-11-16 11:08:06'],
          'dataStatus|1': ['occupy', 'publish'],
          note: '@string',
          'saveStatus|1': ['saving', 'success', 'failure'],
        },
      ],
    })

    await new Promise(resolve => {
      setTimeout(resolve, 1000)
    })
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {
        total: 100,
        records: filelist.list,
      },
    })
  },
)

// 目录树
export const getCategoryTree = http.get('/data/ed/user/file/tree', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMsg: '',
    data: [
      {
        categoryId: '1',
        categoryName: '项目数据',
        children: [
          {
            categoryId: '2',
            categoryName: '初步设计',
          },
          {
            categoryId: '3',
            categoryName: '详细设计阶段',
            children: [
              {
                categoryId: '4',
                categoryName: 'HIRF',
              },
            ],
          },
        ],
      },
      {
        categoryId: '5',
        categoryName: '库文件',
      },
    ],
  })
})

export const getChildFileCount = http.post(
  '/data/ed/user/file/getChildFileCount',
  () => {
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {
        fileCount: 100,
      },
    })
  },
)

export const updateFileInfo = http.post(
  '/data/ed/user/file/updateFileInfo',
  () => {
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {
        fileCount: 100,
      },
    })
  },
)

export const fileMoveFile = http.get('/data/ed/user/file/moveFile', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: true,
  })
})
export const fileCopyFile = http.get('/data/ed/user/file/copyFile', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: true,
  })
})

export const getFileInfo = http.get('/data/ed/user/file/info', () => {
  return HttpResponse.json({
    success: true,
    errorCode: null,
    errorMessage: null,
    data: {
      total: 4,
      records: [
        {
          id: '1873608772342996992',
          fileId: '1873608772342996992',
          fileType: 'pdf',
          fileName: '12月开发prd文档20241211',
          fileNote: null,
          fileVersion: 100,
          parentId: '1872125439691964416',
          dataType: 1,
          dataStatus: 1,
          saveStatus: 1,
          fileSize: 7270653,
          fileSizeShow: '6.93 MB',
          updatedTime: '2024-12-30 05:55:16',
          createdTime: '2024-12-30 05:55:16',
          fileCode: '10000613100241230135515957',
        },
        {
          id: '1873609235217907712',
          fileId: '1873609235217907712',
          fileType: 'docx',
          fileName: '12月开发prd文档20241211',
          fileNote: null,
          fileVersion: 100,
          parentId: '1872125439691964416',
          dataType: 1,
          dataStatus: 1,
          saveStatus: 1,
          fileSize: 16757730,
          fileSizeShow: '15.98 MB',
          updatedTime: '2024-12-30 05:57:06',
          createdTime: '2024-12-30 05:57:06',
          fileCode: '10000615100241230135706314',
        },
        {
          id: '1873609478365904896',
          fileId: '1873609478365904896',
          fileType: 'doc',
          fileName: '二轮开发prd-数据库-20241224',
          fileNote: null,
          fileVersion: 100,
          parentId: '1872125439691964416',
          dataType: 1,
          dataStatus: 1,
          saveStatus: 1,
          fileSize: 19427931,
          fileSizeShow: '18.53 MB',
          updatedTime: '2024-12-30 05:58:04',
          createdTime: '2024-12-30 05:58:04',
          fileCode: '10000614100241230135804280',
        },
        {
          id: '1873609519847571456',
          fileId: '1873609519847571456',
          fileType: 'pdf',
          fileName: '二轮开发prd-数据库-20241224',
          fileNote: null,
          fileVersion: 100,
          parentId: '1872125439691964416',
          dataType: 1,
          dataStatus: 1,
          saveStatus: 1,
          fileSize: 8020871,
          fileSizeShow: '7.65 MB',
          updatedTime: '2024-12-30 05:58:14',
          createdTime: '2024-12-30 05:58:14',
          fileCode: '10000613100241230135814170',
        },
      ],
    },
  })
})

export const fileDetail = http.get('/data/ed/user/file/fileDetail', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: {
      fileName: 'aaa',
      fileType: 'step',
      fileVersion: 100,
      fileNo: '10001013100241210100425223',
      createdBy: '张三',
      createdTime: '2024-12-16 14:25:23',
      updatedTime: '2024-12-16 14:25:23',
      fileSize: '1.3MB',
      fileNote: '我在鼓楼。',
    },
  })
})

//关系新建
export const createRelation = http.post('/data/ed/user/relation/create', () => {
  return HttpResponse.json({
    success: true,
    errorCode: '',
    errorMessage: '',
    data: true,
  })
})
//关系取消
export const cancelRelation = http.get(
  '/data/ed/user/relation/cancel/:relationId',
  () => {
    return HttpResponse.json({
      errorCode: 200,
      errorMessage: '',
      success: true,
      data: true,
    })
  },
)
//修改关系描述
export const updateRelation = http.post('/data/ed/user/relation/update', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: true,
  })
})
//关系列表
export const listRelations = http.get(
  '/data/ed/user/relation/listRelations/:id',
  () => {
    return HttpResponse.json({
      success: true,
      errorCode: null,
      errorMessage: null,
      data: {
        nodes: [
          {
            id: '100000',
            fileName: 'C919',
            fileCode: '10001',
            fileVersion: null,
          },
          {
            id: '100001',
            fileName: 'C929',
            fileCode: '10002',
            fileVersion: null,
          },
          {
            id: '100002',
            fileName: 'APJ',
            fileCode: '10003',
            fileVersion: null,
          },
          {
            id: '100006',
            fileName: '全面试制',
            fileCode: '10007',
            fileVersion: null,
          },
          {
            id: '100008',
            fileName: '优化设计',
            fileCode: '10009',
            fileVersion: null,
          },
        ],
        edges: [
          {
            source: '100008',
            target: '100006',
            relationId: '11111', //关系的主键id
            relationship: 'xxxxxx', //关系描述
          },
          {
            source: '100006',
            target: '100000',
            relationId: '11112', //关系的主键id
            relationship: 'xxxxxx', //关系描述
          },
          {
            source: '100000',
            target: '100001',
            relationId: '11113', //关系的主键id
            relationship: 'xxxxxx', //关系描述
          },
          {
            source: '100000',
            target: '100002',
            relationId: '11114', //关系的主键id
            relationship: 'xxxxxx', //关系描述
          },
        ],
      },
    })
  },
)
//文件作废
export const deleteFile = http.get('/data/ed/user/file/delete', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: true,
  })
})

export const exportFile = http.get('/data/ed/user/file/batchExport', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: true,
  })
})

export const uploadRecord = http.get('/data/ed/user/file/uploadRecord', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: {
      total: 100,
      records: [
        {
          id: '111',
          fileName: 'aaa',
          fileType: '.bbb',
          saveStatus: 1, // 0-上传中 1-上传成功 2-上传失败,
          createdTime: '2024-12-31 12:20:20',
        },
        {
          id: '111',
          fileName: 'aaa',
          fileType: '.bbb',
          saveStatus: 0, // 0-上传中 1-上传成功 2-上传失败,
          createdTime: '2024-12-31 12:20:20',
        },
        {
          id: '111',
          fileName: 'aaa',
          fileType: '.bbb',
          saveStatus: 2, // 0-上传中 1-上传成功 2-上传失败,
          createdTime: '2024-12-31 12:20:20',
        },
      ],
    },
  })
})

export const getVersionView = http.get('/data/ed/user/file/versionView', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: [
      {
        id: '111',
        fileName: 'aaa',
        fileVersion: 100,
        preVersion: null,
        fileCode: '1123',
        effectFlag: 0,
        parentId: '4',
      },
      {
        id: '222',
        fileName: 'aaa',
        fileVersion: 101,
        preVersion: 100,
        fileCode: '11d23',
        effectFlag: 1,
        parentId: '4',
      },
      {
        id: '334',
        fileName: 'aaa',
        fileVersion: 102,
        preVersion: 101,
        fileCode: '1f123',
        effectFlag: 0,
        parentId: '4',
      },
      {
        id: '444',
        fileName: 'aaa',
        fileVersion: 103,
        preVersion: 100,
        fileCode: '112df3',
        effectFlag: 0,
        parentId: '4',
      },
    ],
  })
})
//版本回退
export const versionBack = http.get('/data/ed/user/file/versionBack', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: true,
  })
})
//权限查询
export const getPermission = http.get(
  '/data/ed/user/permission/:fileId',
  () => {
    return HttpResponse.json({
      success: true,
      errorCode: '',
      errorMessage: '',
      data: {
        view: true, //
        move: true, //
        edit: true, //
        delete: true, //
        upload: true, //
        download: true, //
        import: true, //
        export: true, //
      },
    })
  },
)

//检测文件是否存在
export const checkFileNameExist = http.post(
  '/data/ed/user/relation/checkFileNameExist',
  () => {
    return HttpResponse.json({
      errorCode: 200,
      errorMessage: '',
      success: true,
      data: true,
    })
  },
)

//本地文件上传并关联
export const relationUpload = http.post('/data/ed/user/relation/upload', () => {
  return HttpResponse.json({
    errorCode: 200,
    errorMessage: '',
    success: true,
    data: true,
  })
})
